package yxy.cherry.battle.module.affix.skill;

import yxy.cherry.battle.Battle;
import yxy.cherry.battle.Fighter;
import yxy.cherry.battle.NiuBee;
import yxy.cherry.battle.module.affix.AffixContext.AffixAction;
import yxy.cherry.battle.module.affix.AffixContext.AffixActionClass;
import yxy.cherry.battle.module.affix.AffixFactory.SkillTypeEnum;
import yxy.cherry.battle.module.affix.Skill;
import yxy.cherry.battle.module.affix.SkillType;
import yxy.cherry.battle.module.record.stream.RecordStreamGroup;
import yxy.cherry.battle.module.record.stream.RecordStream_04_治疗;
import yxy.cherry.battle.module.record.stream.RecordStream_SKL;
import yxy.cherry.data.bean.skill;

import java.util.Collection;

/** 治疗 */
@SkillType(Type = SkillTypeEnum.治疗)
public class Affix_04_治疗 extends Skill {

	// 条件： 属性类型值
	// 参数1: 回复血量比例
	private double get万分比() {
		return Double.valueOf(getParam(0));
	}

	private int get基础值类型() {
		return getParam(1);
	}

	public Affix_04_治疗(Fighter actor, skill skilldata, int probability, int[] params) {
		super(actor, skilldata, probability, params);
	}

	private RecordStreamGroup steamGroup;

	@Override
	public RecordStreamGroup record() {
		steamGroup = getRecord().stream(new RecordStreamGroup());
		steamGroup.add(new RecordStream_SKL(getActor(), getSkillId()));
		return steamGroup;
	}

	@Override
	public boolean _exec(Collection<Fighter> targets) {
		AffixAction affixAction = getAffixContext().get治疗行动();
		affixAction.set行动者(getActor());
		affixAction.setTargets(targets);
		affixAction.add行动类型(AffixActionClass.主动治疗);

		boolean 有效 = false;
		for (Fighter target : targets) {
			有效 |= _exec(getActor(), target);
		}
		return 有效;
	}

	@Override
	public boolean exec(Fighter actor, Fighter target) {
		if (!target.is活着()) {
			return false;
		}
		getAffixAction().set针对目标(target);

		// 治疗
		long 基础值 = 0;
		switch (get基础值类型()) {
			case 1:
				基础值 = target.get攻击();
			break;
			case 2:// 病人的血量上限
				基础值 = target.get生命();
				break;
			default:// 医生的攻击
				基础值 = actor.get攻击();
				break;
		}

		double treatAdd = 0;
		if (!(actor instanceof NiuBee)) {
			treatAdd = get治疗增幅(actor, target);
		}
		Double 治疗量 = Double.valueOf(基础值) * (get万分比()/VALUE_比率分母) * ((treatAdd+VALUE_比率分母)/VALUE_比率分母);

		long 最终治疗量 = Math.min(治疗量.longValue(),target.get生命()-target.get血量());
		if (最终治疗量 <= 0) {
			return false;
		}

		RecordStream_04_治疗 recordSteam = steamGroup.add(new RecordStream_04_治疗(target,最终治疗量));

		getAffixContext().get治疗行动().getTarget(target).set治疗量(最终治疗量);

		actor.handle治疗();
		target.handle受疗();

		最终治疗量 = getAffixContext().get治疗行动().getTarget(target).get治疗量();
		target.set治疗(最终治疗量);

		// 统计
		getRecord().get统计().getFighter(actor.getFighterPosition()).addCUR(最终治疗量);

		// 流脚本
		recordSteam.record();

		Battle.battleLogger(6,"治疗：施法者："+actor.getName()+"被治疗者："+target.getName()+"依据属性："+get基础值类型()+"比例"+get万分比()+"最终治疗量"+最终治疗量);

		return true;
	}

}